package com.ruoyi.basedata.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.basedata.domain.WfzPerson;
import com.ruoyi.basedata.service.IWfzPersonService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 员工档案Controller
 * 
 * @author xiefeng
 * @date 2022-12-06
 */
@RestController
@RequestMapping("/basedata/person")
public class WfzPersonController extends BaseController
{
    @Autowired
    private IWfzPersonService wfzPersonService;

    /**
     * 查询员工档案列表
     */
    @PreAuthorize("@ss.hasPermi('basedata:person:list')")
    @GetMapping("/list")
    public TableDataInfo list(WfzPerson wfzPerson)
    {
        startPage();
        List<WfzPerson> list = wfzPersonService.selectWfzPersonList(wfzPerson);
        return getDataTable(list);
    }

    /**
     * 导出员工档案列表
     */
    @PreAuthorize("@ss.hasPermi('basedata:person:export')")
    @Log(title = "员工档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WfzPerson wfzPerson)
    {
        List<WfzPerson> list = wfzPersonService.selectWfzPersonList(wfzPerson);
        ExcelUtil<WfzPerson> util = new ExcelUtil<WfzPerson>(WfzPerson.class);
        util.exportExcel(response, list, "员工档案数据");
    }

    /**
     * 获取员工档案详细信息
     */
    @PreAuthorize("@ss.hasPermi('basedata:person:query')")
    @GetMapping(value = "/{fid}")
    public AjaxResult getInfo(@PathVariable("fid") Long fid)
    {
        return success(wfzPersonService.selectWfzPersonByFid(fid));
    }

    /**
     * 新增员工档案
     */
    @PreAuthorize("@ss.hasPermi('basedata:person:add')")
    @Log(title = "员工档案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WfzPerson wfzPerson)
    {
        //获取到当前登录用户的用户名将他设置到属性中
        wfzPerson.setFcreator(getUsername());
        wfzPerson.setFlastupdateuser(getUsername());
        return toAjax(wfzPersonService.insertWfzPerson(wfzPerson));
    }

    /**
     * 修改员工档案
     */
    @PreAuthorize("@ss.hasPermi('basedata:person:edit')")
    @Log(title = "员工档案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WfzPerson wfzPerson)
    {
        //获取到当前登录用户的用户名将他设置到属性中
        wfzPerson.setFlastupdateuser(getUsername());
        return toAjax(wfzPersonService.updateWfzPerson(wfzPerson));
    }

    /**
     * 删除员工档案
     */
    @PreAuthorize("@ss.hasPermi('basedata:person:remove')")
    @Log(title = "员工档案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fids}")
    public AjaxResult remove(@PathVariable Long[] fids)
    {
        return toAjax(wfzPersonService.deleteWfzPersonByFids(fids));
    }
}
